
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>编辑商品</h2>
        <ol class="breadcrumb">
            <li class="active">
               <strong> <a href="index.html">主页</a></strong>
            </li>
            <li>
                <a href="{:U('admin/prodect/prodect')}">编辑商品</a>
            </li>
        </ol>
    </div>
    <div class="col-lg-2">
    </div>
</div>
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <form method="post" action="{:U('admin/prodect/do_edit/id/'.$prodect['id'])}" class="form-horizontal">
            <div class="form-group"><label class="col-sm-1 control-label">商品名称</label>
                <div class="col-sm-10"><input name="title" value="{$prodect.title}" type="text" class="form-control"></div>
            </div>
             <div class="hr-line-dashed"></div>
             <div class="form-group"><label class="col-sm-1 control-label">分类</label>
                <div class="col-sm-2">
                    <select  class="form-control" id="level1">
                        <volist name="level1data" id="l1" >
                        <option value="{$l1.id}" <if condition="$l1['id'] eq $level1">selected="selected"</if>>{$l1.name}</option>
                        </volist>
                    </select>
                </div>
                <div class="col-sm-2">
                    <input type="hidden" id="level2_default" value="{$level2}">
                    <select  class="form-control" id="level2" >
                            <option >请选择一个二级分类</option>  
                    </select>
                </div>
                <div class="col-sm-2">
                    <input type="hidden" id="level2_default" value="{$level2}">
                    <select name="catalog_id" class="form-control" id="level3" >
                            <option >请选择一个三级分类</option>  
                    </select>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
             <div class="form-group"><label class="col-sm-1 control-label">价格</label>
                <div class="col-sm-3"><input name="price" type="text" class="form-control" value="{$prodect.price}"></div>
                <label class="col-sm-1 control-label">库存</label>
                <div class="col-sm-3"><input name="stock" type="text" class="form-control" value="{$prodect.stock}"></div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group"><label class="col-sm-1 control-label">图片</label>
                <div class="col-sm-6"><input name="img" type="text" id="img" class="form-control" value="{$prodect.img}"></div>
                <div class="col-sm-2"><a href="" class="btn btn-info" id="upload">上传</a></div> 
                <div class="col-sm-2" id="preview"></div> 
            </div>
            <div class="hr-line-dashed"></div>
             <div class="form-group"><label class="col-sm-1 control-label">描述</label>
                <div class="col-sm-10"><textarea name="desc" rows="8" class="form-control" >{$prodect.desc}</textarea></div>
            </div>
             <div class="form-group"><label class="col-sm-1 control-label">内容</label>
                <div class="col-sm-10"><textarea name="content"  rows="40" class="form-control" id="content" >{$prodect.content}</textarea></div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group"><label class="col-sm-1 control-label"></label>
                <div class="col-sm-2"><input  type="submit" class="form-control btn btn-info" ></div>
            </div>
            <div class="hr-line-dashed"></div>
        </form>
    </div>
 </div>
<script charset="utf-8" src="__PUBLIC__/other/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="__PUBLIC__/other/kindeditor/lang/zh-CN.js"></script>
<script charset="utf-8" src="__PUBLIC__/other/jquery.upload.js"></script>
<script>
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create(["#content"],{
            uploadJson:"{:U('admin/util/uploadJson')}",
            formatUploadUrl:false,
            allowFlashUpload:false,
            allowMediaUpload:false,
            allowFileUpload:false
        });
        });
    $('#upload').click(function(){
        $.upload({
            // 上传地址
            url: '{:U("/admin/util/upload")}', 
            // 文件域名字
            fileName: 'file', 
            // 其他表单数据
            dataType: 'text',
            // 上传之前回调,return true表示可继续上传
            onSend: function() {
                    return true;
            },
            // 上传之后回调
            onComplate: function(data) {
                //alert(data);
                if(data.indexOf("upload")!=-1){
                    $('#img').val(data);
                    $('#preview').html('<img style="height:89px" src="__ROOT__'+data+'"/>');
                }else{
                    alert(data);
                }      
            }   
        });
        return false;
    })
    function level1change(){
        var id=$("#level1").val();
        $.get("{:U('admin/prodect/getcatalog')}",{id:id},function(data){
            var level2_default=$('#level2_default').val();
            var s="";
            for (var i = 0; i < data.length; i++) {
               var isSelected=data[i].id==level2_default?'selected="selected"':"";
                s = s + '<option '+isSelected+' value="'+data[i].id+'">'+data[i].name+'</option>' ;                          
            };
            $('#level2').html(s);
            level2change();
        })
    }
    function level2change(){
        var id=$("#level2").val();
        $.get("{:U('admin/prodect/getcatalog')}",{id:id},function(data){
            var level3_default=$('#level3_default').val();
            var s="";
            for (var i = 0; i < data.length; i++) {
                 var isSelected=data[i].id==level3_default?'selected="selected"':"";
                s = s + '<option value="'+data[i].id+'">'+data[i].name+'</option>' ;                         
            };
            $('#level3').html(s);
        })
    }
     $('#level1').change(level1change);
      $('#level2').change(level2change);
      level1change();
</script>
